﻿using System;
using Silver3D.Math;

namespace Silver3D.Graphics
{
    /// <summary>
    /// Represents an abstract 3D transformation.
    /// </summary>
    public abstract class Transform : SceneObject
    {
        /// <summary>
        /// The Node that owns this transform.
        /// </summary>
        public Node Parent { get; internal set; }

        public Transform(Scene scene, string id)
            : this(scene, id, null)
        {
        }

        public Transform(Scene scene, string id, Node parent)
            : base(scene, id)
        {
            if (parent != null)
            {
                // Parent property set internally by Node class.
                parent.AddTransform(this);
            }
        }

        /// <summary>
        /// Retrieves the Matrix44 representation of this Transform.
        /// All Transform derived classes must support this method.
        /// </summary>
        /// <returns>The matrix representation.</returns>
        public abstract Matrix44 ToMatrix();

        public override void Detach()
        {
            if (Parent != null) Parent.RemoveTransform(this);
            base.Detach();
        }
    }
}
